<?php 
namespace AliyunOss\Controller;

use AliyunOss\Common\Controller\ModelController;
use Aliyun\OSS\OSSClient;
class IndexController extends ModelController {
    public function __construct() {
        parent::__construct ();
    }
    
    
    
    
    public function index() {
        
        $this -> display();
    }
    public function setAction(){
        C('Alioss.Endpoint', I('Endpoint'));
        C('Alioss.AccessKeyId', I('AccessKeyId'));
        C('Alioss.AccessKeySecret', I('AccessKeySecret'));
        C('Alioss.bucket_name', '');
        session('aliyun', C('Alioss'));
        
        include_once  MODULE_PATH . 'Common/Api/aliyun.class.php';
        
        $this -> aliyun = OSSClient::factory(array(
                'AccessKeyId' => session('aliyun.AccessKeyId'),
                'AccessKeySecret' => session('aliyun.AccessKeySecret'),
                'Endpoint' => session('aliyun.Endpoint'),
        ));
        
        $this -> assign('data', $this -> getListBuckets());
        $this -> display();
    }
    
    private function getListBuckets(){
        $arr = $this -> aliyun ->listBuckets();
        $arr1 = array();
        foreach ($arr as $c){
            array_push($arr1, $c -> getName());
        }
        return $arr1;
    }
    
}